<?php
/*
 * ebiz front
 *
 * HomeView
 *
 * @author allen
 *
 */
require_once '../app/views/BaseView.php';
require_once "../". $GLOBALS["local"] ."/"."home.php";
require_once "../". $GLOBALS["local"] ."/"."utility.php";

class HomeView extends BaseView {

    public $constants;
    public $captchaImg;
    public $user;
    public $notices = array( 
        array('title'=>'关于暂停校园代理服务的公告','href'=>'/u/announcement#100327'),
        array('title'=>'阿基米米2010年春节放假公告','href'=>'/u/announcement#100208'),    
        array('title'=>'阿基米米2009Beta版上线公告','href'=>'/u/announcement#090922'),
        array('title'=>'阿基米米中奖公告','href'=>'/u/announcement#090601'),
        array('title'=>'阿基米米国难日纪念公告','href'=>'/u/announcement#090430'),
        array('title'=>'阿基米米劳动节放假公告','href'=>'/u/announcement#090430'),
        array('title'=>'阿基米米缺货补偿公告','href'=>'/u/announcement#090423'),
        array('title'=>'阿基米米发货延时补偿规则','href'=>'/u/announcement#0904231'),
        array('title'=>'阿基米米春节放假公告','href'=>'/u/announcement#090120')
    );
    public $products;

    public function __construct(){
        parent::__construct();
        $this->constants = get_defined_constants();
    }

    public function getPage(){
        $this->setPageTitle(HOME0016TXT);
        $this->addCSS('1.css');
        $this->addCSS('akimimisytle_index.css');
        $this->addJS('lib/jquery.timers-1.1.3.js',true);
        $this->addJs('frontend.js',true);
        $str_js = "
        <script type='text/javascript'>
            $(function(){
                $('#captchaImg1').css('cursor','pointer');
                $('#captchaImg1').attr('title','{$this->constants['HOME0018TXT']}');
                $('#captchaImg1').click(function(){Login.changeCaptcha();});
                $('.pClassList span:not(.seperator)').hover(
                function(){
                	$(this).addClass('classhover');
                },
                function(){
                	$(this).removeClass('classhover');
                });
                $('.l01_p02 img').hover(
                function(){
                	$(this).css({'border':'solid #55A01E 1px','cursor':'pointer'});
                },
                function(){
                	$(this).css({'border':'solid #E5E5E5 1px'});
                });
                $('.l05_cli img').hover(
                function(){
                	$(this).css({'border':'solid #55A01E 1px','cursor':'pointer'});
                },
                function(){
                	$(this).css({'border':'solid #E5E5E5 1px'});
                });
            });
        </script>
        ";
        $this->setHeadExtends($str_js);
        $header = '';
        $str_result = $header . $this->getContent();
        return $this->getHtmlPage($str_result);
    }

    public function getContent(){
        $str_notices = $this->getNotices();
        $str_image = ConfigConstants::getTImagePath();
        
        $cu_1_title_right = "MP3";
        $cu_2_title_middle = "数码相机";
        $cu_3_title_left = "手机";
        $cu_1_right = $this->getSaleProducts($this->products[0], 3);//第一种分类
        $cu_2_middle = $this->getSaleProducts($this->products[0], 2);//第二种分类
        $cu_3_left = $this->getSaleProducts($this->products[0], 1);//第三种分类
        
        $str_productContent2 = $this->getNormalProducts($this->products[1],"recommend_nav", "推荐商品");
        $str_productContent3 = $this->getNormalProducts($this->products[2],"news_nav", "新品速递");
        $str_productContent4 = $this->getNormalProducts($this->products[3],"hot_nav", "热销商品");
        $str_userlogin = $this->getUserLogin();
        $str_result = <<<str_result
        
<!--flash行开始-->
<div id="flash_row">

    <!--加载login开始-->
    <div class="l_login">
        <div class="login_title">{$this->constants['HOME0017TXT']}</div>
        
        {$str_userlogin}
        
    </div>
    <!--加载login结束-->
    
         <!--加载flash开始-->
            <div id="flash_load" class="f_flash">
                <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
                <title>{$this->constants['HOME0014TXT']}</title>
                <style type="text/css">
                .clear {
                    margin: 0px;
                    padding: 0px;
                    clear: both;
                }
                #play{
                    margin:auto;
                    height:355px;
                    width:540px;
                }
                #play_list{
                    margin:auto;
                    padding:2px;
                    width:530px;
                    height:265px;
                    display:block;
                    overflow:hidden;
                    border:#DEDEDE 1px solid
                }
                #play_list img{
                    width:530px;
                    height:265px;
                    border:0px;
                }

                #play_list a{
                    width:530px;
                    height:265px;
                    text-align:center;
                }
                #small_list{
                    margin:auto;
                    padding:2px 0 2px 3px;
                    width:540px;
                    height:80px;
                }
                .list_img a {
                    float:left;
                    margin:5px 4px 0 2px;
                    width:95px;
                    padding:2px;
                    height:65px;
                    text-align:center;
                    text-decoration:none;
                    border:1px solid orange;
                    FILTER:Alpha(Opacity=80);
                    opacity:0.8;
                }
                .list_img img{
                     width:95px;
                     height:65px;
                     border:0px;
                }
                .list_img a:hover {
                    position:relative;
                    margin:3px 2px 0 1px;
                    padding:2px;
                    width:95px;
                    height:65px;
                    border:3px solid #5C5C5C;
                }
                </style>
                <div id="play">
                    <div id="play_list">
                        <a href="/f/christmas" target='_blank'><img src="{$this->imagePathPrivate}flash/01.jpg"/></a>
                        <a href="/f/newyear" target='_blank'><img src="{$this->imagePathPrivate}flash/02.jpg"/></a>
                        <a href="#" target='_blank'><img src="{$this->imagePathPrivate}flash/03.jpg"/></a>
                        <a href="/f/autumn" target='_blank'><img src="{$this->imagePathPrivate}flash/04.jpg"/></a>
                        <a href="#"><img src="{$this->imagePathPrivate}flash05.jpg"/></a>
                    </div>
                    <div id="small_list">
                        <div class="list_img">
                            <a href="/f/christmas" target='_blank'><img src="{$this->imagePathPrivate}flash/001.jpg"/></a>
                            <a href="/f/newyear" target='_blank'><img src="{$this->imagePathPrivate}flash/002.jpg"/></a>
                            <a href="#" target='_blank'><img src="{$this->imagePathPrivate}flash/003.jpg"/></a>
                            <a href="/f/autumn" target='_blank'><img src="{$this->imagePathPrivate}flash/004.jpg"/></a>
                            <a href="#"><img src="{$this->imagePathPrivate}flash/005.jpg"/></a>
                        </div>
                    </div>
                </div>
            </div>
         <!--加载flash结束-->
         
    <!--加载akimimi-boy开始-->     
    <!--<div class="r_kf" style="padding-top:0px;">
        <img style="width:204px;height:355px;" src="{$str_image}/kf_phone.gif" usemap="#photoMap" border="0" alt="" />
        <map name="photoMap" id="photoMap">
            <area shape="rect" coords="17,310,115,329" href="/u/help?type=mimiboy" />
            <area shape="rect" coords="17,334,109,348" href="/u/help?type=buyprocess" />
        </map>
      </div>-->
    <div class="r_kf">
    	<a href="/u/help?type=mimiboy">了解MIMI-BOY</a>
        <a href="/u/help?type=buyprocess">了解购物流程</a>
    </div>
    <!--加载akimimi-boy结束-->     
    
</div>
<!--flash结束行开始-->
        
<!--公告行开始-->
<div id="post_row">
    <div class="post_border">
        <div class="post_b">
        {$str_notices}
        </div>
    </div>
    <!--cu_xiao begin-->
    <div class="cu_xiao">
        <div class="cu_top">
            <ul>
                <li class="title_1">{$cu_1_title_right}</li>
                <li class="title_1">{$cu_2_title_middle}</li>
                <li class="title_2">{$cu_3_title_left}</li>
            </ul>
        </div>
        <div class="cu_bj">
            <div class="cu_body">
                
                <div class="cu_1" id="cu_1" style="display:none">
                
                {$cu_1_right}
                
                </div>
                 
                <div class="cu_2" id="cu_2" style="display:none">
                
                {$cu_2_middle}
                
                </div>   

                <div class="cu_3" id="cu_3" >
                
                {$cu_3_left}
                
                </div>   
             </div>                                                 
        </div>
        <div class="cu_bottom"><img src="{$this->imagePathPrivate}home_07.jpg" alt="" /></div>
    </div>
    <!--cu_xiao end-->
</div>
<!--公告行结束-->        
        
<!--商品分类开始-->
<div id="class_nav">{$this->constants['HOME0015TXT']}</div>
<div id="class_border">
	<div class="class_b">
    	<div class="class_list">
			<a href='/c/index/mobile_and_accessories' style='text-decoration:none;'><p class="title t1">{$this->constants['HOME0035TXT']}</p></a>
            <p class="text">
			<span><a href="/c/search/21/83/5213">{$this->constants['HOME0201TXT']}</a></span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span><a href="/c/search/21/83/5215">{$this->constants['HOME0202TXT']}</a></span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span><a href="/c/search/21/83/5214">{$this->constants['HOME0203TXT']}</a></span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span><a href="/c/search/21/83/5216">{$this->constants['HOME0204TXT']}</a></span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span><a href="/c/search/21/83/5224">{$this->constants['HOME0205TXT']}</a></span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span><a href="/c/search/21/83/5221">{$this->constants['HOME0206TXT']}</a></span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span><a href="/c/search/21/83/5217">{$this->constants['HOME0207TXT']}</a></span>
			<span class="color01"><a href="/c/search/28">{$this->constants['HOME0038TXT']}</a></span>
            </p>
        </div>
        
    	<div class="class_list">
			<a href='/c/index/notebook_and_accessories' style='text-decoration:none;'><p class="title t3">{$this->constants['HOME0045TXT']}</p></a>
            <p class="text">
			<span onclick="window.location='/c/search/97';" class="">{$this->constants['HOME0046TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span onclick="window.location='/c/search/97/3816/19189';" class="">{$this->constants['HOME0103TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span onclick="window.location='/c/search/97/3816/19188';" class="">{$this->constants['HOME0104TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span onclick="window.location='/c/search/97/3816/19191';" class="">{$this->constants['HOME0105TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span onclick="window.location='/c/search/97/3816/19190';" class="">{$this->constants['HOME0106TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span onclick="window.location='/c/search/137';" class="">{$this->constants['HOME0059TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span onclick="window.location='/c/search/159';">{$this->constants['HOME0052TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span onclick="window.location='/c/search/150';">{$this->constants['HOME0062TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span onclick="window.location='/c/index/peripherals';">{$this->constants['HOME0063TXT']}</span>
            </p>
        </div>
    	<div class="class_list">
			<a href='/c/index/dc_and_accessories' style='text-decoration:none;'><p class="title t4">{$this->constants['HOME0077TXT']}</p></a>
            <p class="text">
			<span class="" onclick="window.location='/c/search/41/89/218';">{$this->constants['HOME0301TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span class="" onclick="window.location='/c/search/41/89/221';">{$this->constants['HOME0302TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span class="" onclick="window.location='/c/search/41/89/220';">{$this->constants['HOME0303TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span class="" onclick="window.location='/c/search/41/89/219';">{$this->constants['HOME0304TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span class="" onclick="window.location='/c/search/41/89/228';">{$this->constants['HOME0305TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span class="" onclick="window.location='/c/search/41/89/223';">{$this->constants['HOME0306TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span class="" onclick="window.location='/c/search/41/89/222';">{$this->constants['HOME0307TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
			<span class="color01" onclick="window.location='/c/search/155';">{$this->constants['HOME0107TXT']}</span>
            </p>
        </div>
        
    	<div class="class_list">
    	    <a href='/c/index/digital_player' style='text-decoration:none;'><p class="title t4">{$this->constants['HOME0079TXT']}</p></a>
            <p class="text">
				<span onclick="window.location='/c/search/171/3297/16306';">{$this->constants['HOME0401TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
				<span onclick="window.location='/c/search/171/3297/16303';">{$this->constants['HOME0402TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
				<span onclick="window.location='/c/search/171/3297/16304';">{$this->constants['HOME0403TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
				<span onclick="window.location='/c/search/171/3297/16305';">{$this->constants['HOME0404TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
				<span onclick="window.location='/c/search/171/3297/16310';">{$this->constants['HOME0405TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
				<span onclick="window.location='/c/search/171/3297/17826';">{$this->constants['HOME0406TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
				<span onclick="window.location='/c/index/dzcd';" class="">{$this->constants['HOME0081TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
				<span onclick="window.location='/c/search/159';" class="color01">{$this->constants['HOME0060TXT']}</span>
            </p>
        </div>   

    	<div class="class_list">
			<a href='/c/index/household' style='text-decoration:none;'><p class="title t7">{$this->constants['HOME0087TXT']}</p></a>
            <p class="text">
				<span onclick="window.location='/c/search/57';" class="">{$this->constants['HOME0098TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
				<span onclick="window.location='/c/search/55';" class="">{$this->constants['HOME0097TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
				<span onclick="window.location='/c/search/160';" class="">{$this->constants['HOME0094TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
				<span onclick="window.location='/c/search/162';" class="">{$this->constants['HOME0093TXT']}</span><span class="seperator">{$this->constants['HOME0034TXT']}</span>
				<span onclick="window.location='/c/search/164';" class="color01">{$this->constants['HOME0099TXT']}</span>
            </p>
        </div> 
        
    <!-- deleted by xiaoyuemian 201003311817
    	<div class="class_hr"></div> 
    -->                             
    </div>
</div>
<!--商品分类结束-->
   
    <div style=' margin:0 auto; height:auto; overflow:hidden; width:970px;'>

        {$str_productContent2}
        {$str_productContent3}
        {$str_productContent4}
</div>
str_result;
        return $str_result;
    }

    /**
     * 用户登录部分
     */
    protected function getUserLogin(){
        if(!$this->user){
            $str_result = <<<str_result
            <div class='login_b'>
            <div class='login_bj'>
                <div class='login_top'>
                    {$this->constants['HOME0001TXT']}<span>100000</span>{$this->constants['HOME0002TXT']}
                    <input type="button" style='cursor:pointer;background:url(//i.akimimi.com/t/default_zh_cn/image/zc_bg1.gif) no-repeat;' onclick="window.location='/u/register';" class="zc_btn" />
                </div>

                <div class="login_text">
                    <form action="" method="post" id="loginForm" onsubmit="javascript:return false;return Login.loginSubmit();" style="margin:0px;">
                	<p class="s_1">
                    	{$this->constants['HOME0005TXT']}
                    	<input type="hidden" id="errorEmailEmpty" value="{$this->constants['LOGINEMAILEMPTY']}" />
	                    <input type="hidden" id="errorEmailError" value="{$this->constants['LOGINEMAILERROR']}" />
	                    <input type="hidden" id="errorPasswordEmpty" value="{$this->constants['LOGINPASSWORDEMPTY']}" />
	                    <input type="hidden" id="errorCaptchaEmpty" value="{$this->constants['CAPTCHAEMPTY']}" />
	                    <input type="hidden" id="errorCaptchaError" value="{$this->constants['CAPTCHAERROR']}" />
	                    <input type="hidden" id="errorLoginError" value="{$this->constants['SUBMITLOGINERROR']}" />                                     	
                	</p>
                    <p class="s_1" id="errorLabel"></p>
                    <p class="s_2"><span>{$this->constants['HOME0006TXT']}：</span><input type="text" class="login_input" id="email1" name="email"/></p>
                    <p class="s_2"><span>{$this->constants['HOME0007TXT']}：</span><input type="password" class="login_input" id="password1" name="password"/></p>
                    <p class="s_3"><span id='captchaImg1'>{$this->captchaImg}</span><input type="hidden" value="ncgegs" id="codedata1" name="codedata"/></p>
                    <p class="s_2"><span>{$this->constants['HOME0009TXT']}：</span><input type="text" id='captcha1' class="login_input" name="captcha"/></p>
                    <p class="s_4"><input type="button" onclick='Login.loginSubmit();' value="{$this->constants['HOME0011TXT']}" class="loginbg05" /></p>
                    </form>
                </div>                
            </div>
            </div>
str_result;
        } else {
            if($this->user['certf']=='3')
                $str_href="'/trade/applypayment' title='{$this->constants['HOME0029TXT']}'>{$this->constants['HOME0024TXT']}";
            else
                $str_href="'/userinfo/modifypassword' title='{$this->constants['HOME0033TXT']}'>{$this->constants['HOME0032TXT']}";
            $str_result = <<<str_result
            <div class='login_b'>
            <div class='login_bj'>
	   			<div class="login_top">
	                {$this->constants['HOME0001TXT']}<span>100000</span>{$this->constants['HOME0002TXT']}
	                <input type="button" style='cursor:pointer;background:url(//i.akimimi.com/t/default_zh_cn/image/zc_bg2.gif) no-repeat;' onclick="window.location='/o/logout';" class="zc_btn" />
	                </div> 
	                <div class="login_text">
	                    <p class="s_5">{$this->user['name']}&nbsp;{$this->constants['HOME0020TXT']}</p>
	                    <p class="s_6">{$this->constants['HOME0021TXT']}</p>
	                    <p class="s_7"><a href='/u/randomp' title='{$this->constants['HOME0031TXT']}'>{$this->constants['HOME0026TXT']}</a></p>
	                    <p class="s_7"><a href='#saleProductsBlock' title='{$this->constants['HOME0027TXT']}'>{$this->constants['HOME0022TXT']}</a></p>
	                    <p class="s_7"><a href='/userinfo/myorderlist' title='{$this->constants['HOME0028TXT']}'>{$this->constants['HOME0023TXT']}</a></p>
	                    <p class="s_7"><a href={$str_href}</a></p>
	                    <p class="s_7"><a href='/userinfo/delivery' title='{$this->constants['HOME0030TXT']}'>{$this->constants['HOME0025TXT']}</a></p>
	                </div>
            </div>
            </div>
str_result;
        }
        return $str_result;
    }

    /**
     * 获取站点公告的内容
     *
     * @return string
     */
    protected function getNotices(){
        $str_result = '';
        foreach ( $this->notices as $key => $arr_notice ){
        	if($key > 7)
        	   continue;
            $str_result.= "<p style='cursor:pointer;'><a onclick=\"window.open('{$arr_notice['href']}');\">{$arr_notice['title']}</a></p>";
        }
        return $str_result;
    }

    /**
     * 促销商品列表
     *
     * @param array $arr_products
     * @param int $int_sort is 1 , 2 , 3
     * @return string
     */
    protected function getSaleProducts($arr_products, $int_sort){
        $str_result = '';
//        foreach ($arr_products as $int_key => $arr_product){
        for ($int_key = ($int_sort - 1) * 5; $int_key < (5 * $int_sort); $int_key++){
//            if($int_key > 4)//只显示前5个产品
//                continue;
            if( !isset($arr_products[$int_key]) )//如果没有产品就不显示
                continue;
            $str_result.= <<<str_result
            <div class="cu_list">
                <img src="{$arr_products[$int_key]['imagesrc']}" alt="{$arr_products[$int_key]['description']}" style="width:118px;height:118pxborder: 1px solid rgb(229, 229, 229); cursor: pointer;" onclick="window.location='/p/{$arr_products[$int_key]['url_title']}';" />
                <p class="title_1"><span>￥</span>{$arr_products[$int_key]['sale_price']}</p>
                <p class="title_2">{$arr_products[$int_key]['description']}</p>                
            </div>
str_result;
        }
        return $str_result;
    }

    /**
     * 其他商品列表
     *
     * @param array $arr_products
     * @param string $int_classNumber
     * @return string
     */
    protected function getNormalProducts($arr_products, $idName, $title){
        $str_result = "
            <div id='{$idName}'>
	            <p class='style_1'/>
				<p class='style_2'>{$title}</p>
				<p class='style_3'/>
            </div>
            <div class='product'>
                <div class='product_bj'>
                    %s
                </div>
            </div>
        ";
        $str_products = '';
        foreach ($arr_products as $int_key => $arr_product){
            if($int_key > 9)
                continue;
            $str_products.= <<<str_products
            
            <div class="pro_list">
	            <a href='/p/{$arr_product['url_title']}'>
	                <img style="width:158px;height:158px" alt="{$arr_product['description']}" src="{$arr_product['imagesrc']}" style="border: 1px solid rgb(229, 229, 229); cursor: pointer;" />
	            </a>
			    <p class="title_1">
			        <span>￥</span>{$arr_product['sale_price']}
			    </p>
			    <p class="title_2">{$arr_product['description']}</p>
			</div>
            
			
str_products;
        }
        return sprintf($str_result,$str_products);
    }

}


